<?php
//
//namespace catchAdmin\phone\controller;
//
//
//use catcher\base\CatchRequest;
//use catcher\CatchUpload;
//
//class Phoneupload
//{
//    protected $attachment;
//
////    public function __construct(Attachments $attachment)
////    {¬
////        $this->attachment = $attachment;
////    }
//
//    /**
//     * image upload
//     *
//     * @time 2020年01月25日
//     * @param CatchRequest $request
//     * @param CatchUpload $upload
//
//     */
//    public function image(CatchUpload $upload)
//    {
//
//        $file = request()->file('file');
//        // 上传到本地服务器
//        $savename = \think\facade\Filesystem::putFile( 'topic', $file);
//
//        p($savename);
//    }
//}


namespace catchAdmin\phone\controller;

use catchAdmin\system\model\Attachments;
use catcher\base\CatchRequest;
use catcher\CatchResponse;
use catcher\CatchUpload;
use catcher\exceptions\FailedException;
use catcher\facade\FileSystem;
use think\facade\Request;
use think\Image;

class Phoneupload
{
    protected $attachment;

//    public function __construct(Attachments $attachment)
//    {
//        $this->attachment = $attachment;
//    }

    /**
     * image upload
     *
     * @time 2020年01月25日
     * @param CatchRequest $request
     * @param CatchUpload $upload
     */
    public function image( CatchUpload $upload)
    {
        $file = request()->file('file');
        // 上传到本地服务器
        $savename = \think\facade\Filesystem::putFile( 'topic', $file);



        //topic/20230822/646f8431e2d88cbaf748783110c0a308.jp

        $images = Image::open(app()->getRootPath() ."public/images/".$savename);
        $images->thumb(1000,1000)->save(app()->getRootPath() ."public/images/".$savename);
//
//        $images = array_values(Request::file());
//        if (!count($images)) {
//            throw new FailedException('请选择图片上传');
//        }
//        $img = $upload->checkImages($file)->multiUpload(
//            count($file) < 2 ? $images[0] : $images
//        );
        return CatchResponse::success(Request::instance()->domain().'/images/'.$savename);


    }
}